package com.baizhi.wd.action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baizhi.wd.entity.User;
import com.baizhi.wd.service.UserService;
import com.baizhi.wd.service.UserServiceImpl;

public class LoginAction extends HttpServlet {
	public void service(HttpServletRequest request,HttpServletResponse response) throws IOException{
	try{
	//1获取client的请求数据
	request.setCharacterEncoding("utf-8");
	String name = request.getParameter("username");
	String pwd = request.getParameter("password");
	//2 调用业务类的方法，检查帐号
	UserService service = new UserServiceImpl();
	User user = service.queryOne(name);
	//3 检查结果
	if(user.getUsername().equals(name)&&user.getPassword().equals(pwd)){
		//跳转--重定向
		response.sendRedirect("/telbook_2/per/queryAllAction");
		/*RequestDispatcher rd = request.getRequestDispatcher("/per/queryAllAction");
		rd.forward(request, response);*/
	}else{
		RequestDispatcher rd = request.getRequestDispatcher("/LoginView.html");
		rd.forward(request, response);
	}

	
	}catch(Exception e){
		response.sendRedirect("/telbook_2/catchError");
		e.printStackTrace();
		}
	}
}
